package com.battle.project;

import com.battle.project.order.properties.AsyncThreadPoolProperties;
import com.battle.project.order.properties.RabbitMqProperties;
import com.battle.project.order.properties.ThreadPoolProperties;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.scheduling.annotation.EnableAsync;

import java.util.concurrent.TimeUnit;

@SpringBootApplication
@EnableFeignClients
@EnableConfigurationProperties({AsyncThreadPoolProperties.class, ThreadPoolProperties.class, RabbitMqProperties.class})
@EnableAsync
public class OrderWebApplication {

    public static void main(String[] args) throws InterruptedException {
        ConfigurableApplicationContext applicationContext = SpringApplication.run(OrderWebApplication.class, args);

//        while(true) {
        //当动态配置刷新时，会更新到 Enviroment中，因此这里每隔一秒中从Enviroment中获取配置
        String sex = applicationContext.getEnvironment().getProperty("user.sex");
        String phone = applicationContext.getEnvironment().getProperty("user.phone");
        String age = applicationContext.getEnvironment().getProperty("user.age");
        String name = applicationContext.getEnvironment().getProperty("user.name");
        System.err.println("user name :" + name + "; age: " + age + "; sex: " + sex + "; phone: " + phone);
        TimeUnit.SECONDS.sleep(1);
//        }


    }

}
